#ifndef GLOBAL_H
#define GLOBAL_H

#define F_CPU 22118400UL

#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>
#include <util/delay.h> 

#include "avrlibdefs.h"
#include "avrlibtypes.h"
#define u08 unsigned char
#define u16 unsigned short
#define u32 unsigned long
#define s08 char
#define s16 short
#define s32 int


/* Part 1: Macro definitions */

#define CONTROL_PORT PORTD
#define CONTROL_DDR  DDRD

// #if defined(__AVR_ATtiny2313__)
// /* no PD7 and no ADC available on ATtiny2313 */
// #  define TRIGGER_DOWN PD2
// #  define TRIGGER_UP   PD3
// #  define FLASH	       PD4
// #  define CLOCKOUT     PD6
// #else
// #  define TRIGGER_DOWN PD2
// #  define TRIGGER_UP   PD3
// #  define TRIGGER_ADC  PD4
// #  define CLOCKOUT     PD6
// #  define FLASH	       PD7
// #endif

// #if defined(__AVR_ATmega16__)
// #  define PWMDDR     DDRD
// #  define PWMOUT     PD5
// #elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__)
// #  define PWMDDR     DDRB
// #  define PWMOUT     PB1
// #elif defined(__AVR_ATtiny2313__)
// #  define PWMDDR     DDRB
// #  define PWMOUT     PB3
// #  define HAVE_ADC   0
// #  define USART_RXC_vect USART_RX_vect
// #  define MCUCSR     MCUSR
// #else
// #  error "Unsupported MCU type"
// #endif
#define __AVR_ATmega325p__

#if defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega325p__)
/* map ATmega8/16 names to ATmegaX8 names */
#  define USART_RXC_vect USART_RX_vect
#  define UDR     UDR0
#  define UCSRA   UCSR0A
#  define UCSRB   UCSR0B
#  define FE      FE0
#  define TXEN    TXEN0
#  define RXEN    RXEN0
#  define RXCIE   RXCIE0
#  define UDRE    UDRE0
#  define U2X     U2X0
#  define UBRRL   UBRR0L

//#  define TIMSK0   TIMSK0
#  define MCUCSR  MCUSR
#endif

// #if !defined(HAVE_ADC)
// #  define HAVE_ADC 1
// #endif

#endif
